# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
        
class Task_GetReward(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))

        btnMoreMission = poco("more_mission")
        if btnMoreMission.exists():
            self.clickButton(btnMoreMission)

        try:
            poco("MissionCenterLayer").wait_for_appearance()
        except:
            assert_equal(False, True, "任务中心正常弹出")
            return False

        missionCenterLayer = poco("MissionCenterLayer")

        bonusInfo = missionCenterLayer.offspring("bonus_info")
        txtScore = bonusInfo.offspring("score")
        curTicketNum = int(txtScore.get_text())

        taskList = missionCenterLayer.offspring("task_list")
        taskItems = taskList.offspring("template")
        for i in range(0, len(taskItems)):
            txtName = taskItems[i].child("name").get_text()
            if txtName == "每日分享":
                btnGetReward = taskItems[i].offspring("process_btn")
                if btnGetReward.exists():
                    self.clickButton(btnGetReward)
                break

        receiveLayer = poco("MissionRecRewardLayer")
        btnReceive = receiveLayer.offspring("receive")
        if btnReceive.exists():
            self.clickButton(btnReceive)

        poco.swipe([0.5, 0.5], [0.5, 0.2], None, 0.5)
        sleep(2.0)
        snapshot()

        titleBar = missionCenterLayer.offspring("titile_bar")
        btnClose = titleBar.child("back")
        if btnClose.exists():
            self.clickButton(btnClose)

        return True
        
_instance = Task_GetReward()
runTest = _instance.runTest